package com.zisu.aradvertising.controller;

import com.zisu.aradvertising.pojo.Creater;
import com.zisu.aradvertising.pojo.Result;
import com.zisu.aradvertising.service.CreaterService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/creater")
public class CreaterController {
    @Resource
    private CreaterService createrService;

    //登录控制
    @PostMapping("/login")
    public Result<Creater> loginController(@RequestParam String cphone, @RequestParam String cpassword) {
        Creater creater = createrService.loginService(cphone, cpassword);
        if (creater != null) {
            return Result.success(creater, "登录成功!");
        } else {
            return Result.error("123", "账号密码错误!");
        }
    }

    //注册控制
    @PostMapping("/register")
    public Result<Creater> registController(@RequestBody Creater newCreater) {
        Creater creater = createrService.registService(newCreater);
        if (creater != null) {
            return Result.success(creater, "注册成功！");
        } else {
            return Result.error("456", "该电话号码已被注册过！");
        }
    }

    //修改密码控制
    @PostMapping("/edit")
    public Result<Creater> editController(@RequestParam String cphone, @RequestParam String cpassword) {
        Creater creater = createrService.updatepasswordService(cphone, cpassword);
        if (creater != null) {
            return Result.success(creater, "修改密码成功！");
        } else {
            return Result.error("456", "电话号码错误！");
        }
    }

    //返回所有视频创作者
    @PostMapping("/findall")
    public Result<List<Creater>> findallConroller() {
        List<Creater> list = createrService.findallService();
        if (list != null) {
            return Result.success(list, "查询成功");
        } else {
            return Result.error("123", "查询失败!");
        }
    }
    //返回一个合作单号下广告商
    @PostMapping("/findbycoid")
    public Result<Creater> findbycoudController(int coid ){
        Creater creater = createrService.findbycoidService(coid);
        if (creater != null) {
            return Result.success(creater, "查询成功");
        } else {
            return Result.error("123", "查询失败!");
        }
    }
    //返回创作者个人信息
    @PostMapping("/findbycid")
    public Result<Creater> findbycidController(int cid ){
        Creater creater = createrService.findbycidService(cid);
        if (creater != null) {
            return Result.success(creater, "查询成功");
        } else {
            return Result.error("123", "查询失败!");
        }
    }



}
